import { segment } from "oicq";

//项目路径
const _path = process.cwd();

//拿到这插件就没有标明原作者，感谢这位大佬写的V2

//V3由果丁修改qq985318935，qq群625882201（宣传下自己的小群/狗头）

//天选之人就是禁言一分钟套餐

let tx = {};

//是否启用谁发谁禁言
let tututu = false;

export class run extends plugin {
	constructor() {
		super({
			name: '天选之人',
			dsc: '天选之人',
			/** https://oicqjs.github.io/oicq/#events */
			event: 'message',
			priority: 1000,
			rule: [{
				/** 命令正则匹配 */
        reg: "^天选之人$", //匹配消息正则，命令正则
				/** 执行方法 */
				fnc: 'whoismyGay'
			}
    ]
		})
   
	}


async whoismyGay(e) {

    if (!e.isGroup) {
        return true;
    }

    if (tx[e.group_id]) {
        Bot.pickGroup(e.group_id).muteMember(tx[e.group_id].user_id, 0);
    }

    let mmap = await e.group.getMemberMap();

    let arrMember = Array.from(mmap.values()).filter(member => member.role == "member");;

    let randomGay = arrMember[Math.round(Math.random() * (arrMember.length - 1))];

    let name = randomGay.card;
    if (name.length == 0) {
        name = randomGay.nickname;
    }
    let who = randomGay.user_id;

    if (tututu) {
        who = e.user_id;
        name = e.sender.card;
        if (name.length == 0) {
            name = e.sender.nickname;
        }
    }
    e.group.muteMember(who, 60);

    tx[e.group_id] = { user_id: who };

    e.reply(`本轮天选之人是 【${name}】 (${who})  恭喜你喜提1分钟禁言套餐！`);
    return true; //返回true 阻挡消息不再往下
    }
 }
